package mamikeji.liaowa.ui.activity.right.setting;

import android.app.Dialog;
import android.content.Intent;
import android.graphics.Typeface;
import android.net.Uri;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import mamikeji.liaowa.R;
import mamikeji.liaowa.ui.activity.BaseActivity;

public class Set_AboutActivity extends BaseActivity implements View.OnClickListener {
    private RelativeLayout relativeLayout_set_about_customer
            , relativeLayout_set_about_help
            , relativeLayout_set_about_service
            , relativeLayout_set_about_appedition;
    private TextView textView_about_jieshao;
    private Dialog dialog_cache;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_set__about);
        getBase();
        setTitleLeftBtn();
        setTitleName(R.string.set_about_name);
        init();
        initData();
        getDigLog();
    }

    /**
     * 加载布局控件
     */
    private void init() {
        relativeLayout_set_about_customer = (RelativeLayout) findViewById(R.id.relativeLayout_set_about_customer);
        relativeLayout_set_about_help = (RelativeLayout) findViewById(R.id.relativeLayout_set_about_help);
        relativeLayout_set_about_service = (RelativeLayout) findViewById(R.id.relativeLayout_set_about_service);
        relativeLayout_set_about_appedition = (RelativeLayout) findViewById(R.id.relativeLayout_set_about_appedition);

        textView_about_jieshao = (TextView) findViewById(R.id.textView_about_jieshao);

        relativeLayout_set_about_customer.setOnClickListener(this);
        relativeLayout_set_about_help.setOnClickListener(this);
        relativeLayout_set_about_service.setOnClickListener(this);
        relativeLayout_set_about_appedition.setOnClickListener(this);
    }

    /**
     * 初始化数据
     */
    private void initData() {
        /*
         * 必须事先在assets底下创建一fonts文件夹 并放入要使用的字体文件(.ttf)
         * 并提供相对路径给creatFromAsset()来创建Typeface对象
         */
        Typeface fontFace = Typeface.createFromAsset(getAssets(),
                "fonts/main_text_css.ttf");
        // 字体文件必须是true type font的格式(ttf)；
        // 当使用外部字体却又发现字体没有变化的时候(以 Droid Sans代替)，通常是因为
        // 这个字体android没有支持,而非你的程序发生了错误
        textView_about_jieshao.setTypeface(fontFace);
    }

    @Override
    public void onClick(View view) {
        Intent mIntent = null;
        switch (view.getId()) {
            case R.id.relativeLayout_set_about_customer:
                dialog_cache.show();
                break;
            case R.id.relativeLayout_set_about_help:
                mIntent = new Intent(Set_AboutActivity.this,Set_WebActivity.class);
                mIntent.putExtra("set_type",1);
                break;
            case R.id.relativeLayout_set_about_service:
                mIntent = new Intent(Set_AboutActivity.this,Set_WebActivity.class);
                mIntent.putExtra("set_type",2);
                break;
            case R.id.relativeLayout_set_about_appedition:
                mIntent = new Intent(Set_AboutActivity.this,Set_WebActivity.class);
                mIntent.putExtra("set_type",3);
                break;
            case R.id.relativeLayout_set_dig_btnerror:
                dialog_cache.hide();
                break;
            case R.id.relativeLayout_set_dig_query:
                dialog_cache.hide();
                startActivity(new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + "40012345678")));//跳转到拨号界面，同时传递电话号码
                break;
        }
        if (mIntent != null){
            startActivity(mIntent);
        }
    }

    private TextView textView_dig_cache_text , textView_set_dig_query , textView_set_dig_btnerror;
    private RelativeLayout relativeLayout_set_dig_btnerror, relativeLayout_set_dig_query;

    private void getDigLog() {
        dialog_cache = new Dialog(Set_AboutActivity.this, R.style.DialogLoading);
        View inflate = LayoutInflater.from(Set_AboutActivity.this).inflate(R.layout.diglog_set_clearcache, null);
        dialog_cache.setContentView(inflate);

        textView_dig_cache_text = (TextView) inflate.findViewById(R.id.textView_dig_cache_text);
        textView_set_dig_query = (TextView) inflate.findViewById(R.id.textView_set_dig_query);
        textView_set_dig_btnerror = (TextView) inflate.findViewById(R.id.textView_set_dig_btnerror);
        relativeLayout_set_dig_btnerror = (RelativeLayout) inflate.findViewById(R.id.relativeLayout_set_dig_btnerror);
        relativeLayout_set_dig_query = (RelativeLayout) inflate.findViewById(R.id.relativeLayout_set_dig_query);

        textView_dig_cache_text.setText(R.string.set_about_phonenum);
        textView_set_dig_query.setText(R.string.set_about_phonedial);
        textView_set_dig_btnerror.setText(R.string.set_about_phonecancel);

        relativeLayout_set_dig_btnerror.setOnClickListener(this);
        relativeLayout_set_dig_query.setOnClickListener(this);
    }
}
